//
//  HomeViewController.m
//  WKWebViewOC
//
//  Created by 孟令冬 on 2018/4/3.
//  Copyright © 2018年 XiaoFeng. All rights reserved.
//

#import "HomeViewController.h"
#import <JavaScriptCore/JavaScriptCore.h>

@interface HomeViewController ()<UIWebViewDelegate>
@property (strong,nonatomic) UIWebView * webView;
@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height - 20)];
    self.webView.backgroundColor = [UIColor whiteColor];
    self.webView.delegate = self;
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: [[NSURL alloc] initWithString:@"http://testgt.caibangw.com:8880/#/home"]];
    [self.webView loadRequest:request];
    [self.view addSubview:self.webView];
    // Do any additional setup after loading the view.
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    NSURL *URL = request.URL;
    NSString *scheme = [URL scheme];
    NSLog(@"scheme----%@",scheme);
    NSLog(@"URL----%@",URL);
    
    NSString *jsString = [NSString stringWithFormat:@"localStorage.getUserAgen(%@'", @"iOS"];
    [self.webView stringByEvaluatingJavaScriptFromString:jsString];
//    JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
//    [context evaluateScript:[NSString stringWithFormat:@"javascript:getUserAgen(%@)",@"iOS"]];

    
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
